package ch11;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

class _18_HashMapEx2 {
	public static void main(String[] args) {
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		map.put("john", 90);
		map.put("john", 100);
		map.put("alice", 100);
		map.put("jenifer", 80);
		map.put("kara", 90);

		Set<Map.Entry<String,Integer>> set = map.entrySet();
		for(Map.Entry<String,Integer> e:set)
			System.out.println("[" + e.getKey() + ","	+ e.getValue() + "]");
		/*
		[john,100]
		[alice,100]
		[jenifer,80]
		[kara,90]
		*/

		Set<String> keySet = map.keySet();
		System.out.println("name list: " + keySet); 
		// name list: [john, alice, jenifer, kara]

		Collection<Integer> values = map.values();		
		int total = 0;
		for(int value:values) total += value;
		System.out.println("total: " + total);
		System.out.println("average: " + (float) total / set.size());
		System.out.println("max: " + Collections.max(values));
		System.out.println("min: " + Collections.min(values));
		/*
		total: 370
		average: 92.5
		max: 100
		min: 80
		*/
	}
}